package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TbGoodsDict;
import com.ruoyi.business.service.ITbGoodsDictService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货物字典管理Controller
 * 
 * @author ruoyi
 * @date 2021-04-23
 */
@Controller
@RequestMapping("/business/dict")
public class TbGoodsDictController extends BaseController
{
    private String prefix = "business/dict";

    @Autowired
    private ITbGoodsDictService tbGoodsDictService;

    @RequiresPermissions("business:dict:view")
    @GetMapping()
    public String dict()
    {
        return prefix + "/dict";
    }

    /**
     * 查询货物字典管理列表
     */
    @RequiresPermissions("business:dict:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbGoodsDict tbGoodsDict)
    {
        startPage();
        List<TbGoodsDict> list = tbGoodsDictService.selectTbGoodsDictList(tbGoodsDict);
        return getDataTable(list);
    }

    /**
     * 导出货物字典管理列表
     */
    @RequiresPermissions("business:dict:export")
    @Log(title = "货物字典管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbGoodsDict tbGoodsDict)
    {
        List<TbGoodsDict> list = tbGoodsDictService.selectTbGoodsDictList(tbGoodsDict);
        ExcelUtil<TbGoodsDict> util = new ExcelUtil<TbGoodsDict>(TbGoodsDict.class);
        return util.exportExcel(list, "货物字典管理数据");
    }

    /**
     * 新增货物字典管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存货物字典管理
     */
    @RequiresPermissions("business:dict:add")
    @Log(title = "货物字典管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbGoodsDict tbGoodsDict)
    {
        return toAjax(tbGoodsDictService.insertTbGoodsDict(tbGoodsDict));
    }

    /**
     * 修改货物字典管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbGoodsDict tbGoodsDict = tbGoodsDictService.selectTbGoodsDictById(id);
        mmap.put("tbGoodsDict", tbGoodsDict);
        return prefix + "/edit";
    }

    /**
     * 修改保存货物字典管理
     */
    @RequiresPermissions("business:dict:edit")
    @Log(title = "货物字典管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbGoodsDict tbGoodsDict)
    {
        return toAjax(tbGoodsDictService.updateTbGoodsDict(tbGoodsDict));
    }

    /**
     * 删除货物字典管理
     */
    @RequiresPermissions("business:dict:remove")
    @Log(title = "货物字典管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbGoodsDictService.deleteTbGoodsDictByIds(ids));
    }
}
